<!doctype html>
<html lang="en" >
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style type="text/css">
        html,body,.map{
            width: 100%;
            background:white!important;
            height: 100%;
            margin: 0px;
        }
    </style>
    <title>简易行政区地图标注</title>
</head>
<body>
<div id="container" class="map" tabindex="0"></div>
<!--<script type="text/javascript" src='https://a.amap.com/jsapi_demos/static/citys.js'></script>-->

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=5a9c772a575a8a038a65209bbbc6fb2b&plugin=Map3D,AMap.DistrictLayer,AMap.Scale,AMap.ToolBar"></script>
<script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/data/china-pp.js"></script>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript">
    // var citys = [{"lnglat":[117.227267,31.820567],"name":"安徽省合肥市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省合肥市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省淮北市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省淮南市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省六安市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省铜陵市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省芜湖市","title":""},{"lnglat":[117.227267,31.820567],"name":"安徽省芜湖市","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""},{"lnglat":[116.365850,39.912600],"name":"北京市朝阳区","title":""}]
    var SOC = 'CHN'
    var colors = {};
    var GDPSpeed = {
        '520000':10,//贵州
        '540000':10,//西藏
        '530000':8.5,//云南
        '500000':8.5,//重庆
        '360000':8.5,//江西
        '340000':8.0,//安徽
        '510000':7.5,//四川
        '350000':8.5,//福建
        '430000':8.0,//湖南
        '420000':7.5, //湖北
        '410000':7.5,//河南
        '330000':7.0,//浙江
        '640000':7.5,//宁夏
        '650000':7.0,//新疆
        '440000':7.0,//广东
        '370000':7.0,//山东
        '450000':7.3,//广西
        '630000':7.0,//青海
        '320000':7.0,//江苏
        '140000':6.5,//山西
        '460000':7,// 海南
        '310000':6.5,//上海
        '110000':6.5, // 北京
        '130000':6.5, // 河北
        '230000':6, // 黑龙江
        '220000':6,// 吉林
        '210000':6.5, //辽宁
        '150000':6.5,//内蒙古
        '120000':5,// 天津
        '620000':6,// 甘肃
        '610000':8.5,// 甘肃
        '710000':2.64, //台湾
        '810000':3.0, //香港
        '820000':4.7 //澳门

    }
    var getColorByDGP = function(adcode){
        if(!colors[adcode]){
            var gdp = GDPSpeed[adcode];
            if(!gdp){
                colors[adcode] = 'rgb(21,51,149)'
            }else{
                var r = 255;
                var g = 200;
                var b = 32;
                var a = gdp/10;
                colors[adcode] = 'rgba('+ r +','+ g +','+b+','+a+')';
            }
        }
        console.log(colors[adcode]);
        return colors[adcode]
    }
    var disCountry = new AMap.DistrictLayer.Country({
        zIndex:10,
        SOC:'CHN',
        depth:1,
        styles:{
            'nation-stroke':'#ffc400',
            'coastline-stroke':'#fdfdfd',
            'province-stroke':'#888888',
            // 'fill':function(props){
            //     return getColorByDGP(props.adcode_pro)
            // }
            'fill':'rgb(21,51,149)'
        }
    })

    var map = new AMap.Map("container",{
        zooms: [4, 8],
        center:[106.122082,33.719192],
        zoom: 4,
        isHotspot:false,
        defaultCursor:'pointer',
        layers:[
            disCountry
        ],
        mapStyle: 'amap://styles/whitesmoke',
        viewMode:'2D',
        resizeEnable: true
    })




    map.on('complete', function () {
        // 创建 AMap.LabelsLayer 图层
        var layer = new AMap.LabelsLayer({
            zooms: [3, 20],
            zIndex: 1000,
            collision: false
        });

        // 将图层添加到地图
        map.add(layer);

        var markers = [];
        var positions ;

        var icon = {
            type: 'image',
            image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
            size: [16, 19],
            anchor: 'bottom-center',
        };

        for (var i = 0; i < citys.length; i++) {
            var curPosition = citys[i];
            var curData = {
                position: curPosition.lnglat,
                title: curPosition.title,
                icon
            };

            var labelMarker = new AMap.LabelMarker(curData);

            markers.push(labelMarker);

            // 给marker绑定事件
            labelMarker.on('mouseover', function(e){

                var position = e.data.data && e.data.data.name;
                console.log(position);
                if(position){
                    normalMarker.setContent(
                        '<div class="amap-info-window">'
                        + position +
                        '<div class="amap-info-sharp"></div>' +
                        '</div>');
                    normalMarker.setPosition(position);
                    map.add(normalMarker);
                }
            });

            labelMarker.on('mouseout', function(){
                map.remove(normalMarker);
            });
        }

        // 一次性将海量点添加到图层
        layer.add(markers);

        // 普通点
        var normalMarker = new AMap.Marker({
            anchor: 'bottom-center',
            offset: [0, -15],
        });
    });
</script>
</body>

</html>
